package com.mt.channel.service.impl;

import java.util.List;
import java.util.Map;


import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.channel.api.service.IChannelOrderService;
import com.mt.channel.entity.ChannelAccountEntity;
import com.mt.channel.entity.ChannelOrderEntity;
import com.mt.channel.service.model.ChannelOrderServiceModel;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import org.springframework.stereotype.Service;

@Service
public class ChannelOrderServiceImpl implements IChannelOrderService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelOrderServiceImpl.class);

    @Autowired
    private ChannelOrderServiceModel channelOrderServiceModel;

    public ServiceResult<ChannelOrderEntity> findInfo(Map<String, Object> params) {
        // 查询用户信息
        ServiceResult<ChannelOrderEntity> result = null;
        // 该参数标识前段是否需要权限数据
        try {
            result = channelOrderServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<ChannelOrderEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<ChannelOrderEntity>> result = new ServiceResult<List<ChannelOrderEntity>>();
        try {
            result = channelOrderServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> doInsert(ChannelOrderEntity channelOrderEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelOrderServiceModel.insert(channelOrderEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> findCount(Map<String, Object> params) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelOrderServiceModel.selectCount(params);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][findCount]：query findCount occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doInsertRelate(ChannelOrderEntity channelOrderEntity,
        ChannelAccountEntity channelAccountEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelOrderServiceModel.insertRelate(channelOrderEntity, channelAccountEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdateRelate(ChannelOrderEntity channelOrderEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelOrderServiceModel.updateRelate(channelOrderEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer channelOrderId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelOrderServiceModel.deleteByPrimaryKey(channelOrderId);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(ChannelOrderEntity channelOrderEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelOrderServiceModel.updateByPrimaryKeySelective(channelOrderEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelOrderServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

}
